// packageI/anytime_service/my/DemandManage/DemandManage.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:1,
    language:"",
    page:1,
    total_page:1,
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
    this.getData();
  },
  getData(page =1 ){
    app._getNetWork({
      url:app.getNetAddresss('plugin.be-within-call.frontend.publish.need'),
      data:{
        state:this.data.active,
        page
      },
      success:resdata=>{
        let {result,data} = resdata.data;
        if(result){
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
            if(page == 1){
              this.setData({list:data.data})
            }else{
              let list = this.data.list.concat(data.data);
              this.setData({list})
            }
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onClick(e){
    this.setData({active:e.detail.name});
    this.getData()
  },
  check_order(e){
    let order_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url:`/packageJ/anytime_service/order/order_detail/index?type=individual&order_id=${order_id}`
    })
  },
  link(e){
    let {id,apply_status}= e.currentTarget.dataset.item;
    let type= '';
    if(apply_status==-11){
      type = 1
    }else{
      type = 2
    }
    wx.navigateTo({
      url: '/packageJ/anytime_service/my/Demand/Demand?type='+type+'&demand_id='+id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.page>=this.data.total_page){
      return;
    }
    let page = this.data.page+ 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})